package com.sfc.client.util;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ProcessUtil {

    public static void main(String[] args) {
        System.out.println(cutUser());
    }

    private static String getCmd(String str) {
        Process proc;
        StringBuffer sb = new StringBuffer();
        try {
            proc = Runtime.getRuntime().exec(str);
            InputStream is = proc.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"GBK"));
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line+"\n");
            }
            proc.waitFor();
            is.close();
            reader.close();
            proc.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

    private static String getWinUser() {
        String cmdStr = "net user";
        return getCmd(cmdStr);
    }

    private static String cutUser() {
        String cmdStr = "runas /user:lizhenwei 123456 powershell";
        return getCmd(cmdStr);
    }

}
